package akjvm.tools.java.classpath;

import java.io.File;
import java.io.IOException;

/**
 * Created by VictoryWang on 2016/6/22.
 */
public class CompositeEntry extends Entry{
    private Entry[] entries;

    public CompositeEntry(String path) throws IOException {
        String[] paths = path.split(File.pathSeparator);
        entries = new Entry[paths.length];
        for (int i = 0; i < paths.length; i++) {
            entries[i] = newEntry(paths[i]);
        }

    }

    @Override
    public byte[] readClass(String className) throws IOException {
        for (Entry entry : entries) {
            byte[] clazz = entry.readClass(className);
            if (clazz != null) {
                return clazz;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (Entry entry : entries) {
            sb.append(entry.toString());
        }
        return sb.toString();
    }
}
